import React,{useEffect} from "react";
let observer:any;
export default function useObserverHook(ele: any,callback: (arg0: IntersectionObserverEntry[]) => any,watch:any=[]){
    useEffect(()=>{
        const node = document.querySelector(ele)
        if(node){
            observer = new IntersectionObserver(enteries =>{
                callback && callback(enteries)
            });
            observer.observe(node)
        }
        
        return (()=>{
            if(observer && node){
               observer.unobserve(node)
                observer.disconnect()
            }
        })
    },watch)
}
